﻿#ifndef SWANLINK_FINANCE_CARDSENDER_ADAPTOR_F5G006_LIB_LIBF5G006_INCLUDE_F5G006_DS_H
#define SWANLINK_FINANCE_CARDSENDER_ADAPTOR_F5G006_LIB_LIBF5G006_INCLUDE_F5G006_DS_H

#include "transport.h"
#include <memory>

class F5G006_DeviceService {
 public:
    uint8_t* m_pLastRDT;
    uint16_t m_lastRDTSize;

 public:
    explict F5G006_DeviceService(std::unique_ptr<Transport> transport);
    ~F5G006_DeviceService();

    int doCommand(uint8_t CC1, uint8_t CC2, long timeoutVal);
    int doCommand(uint8_t CC1, uint8_t CC2, const void* pbCMP, int CMPSize, long timeoutVal);

 private:
    int initCommandMessage(uint8_t CC1, uint8_t CC2, const void* pbCMP, int CMPSize, int& msgLen);
    int waitForACK(long timeoutVal, uint8_t& bAns);
    int recvResponse(long timeoutVal, int &msgLen);
    int checkLastResponse(uint8_t CC1, uint8_t CC2, int msgLen);

 private:
    static const int MAX_MSG_SIZE = 1024;
    static const int MIN_MSG_SIZE = 10;
    static const int MIN_P_MSG_SIZE = 11;
    uint8_t m_msgBuf[MAX_MSG_SIZE];

    std::unique_ptr<Transport> m_transport;
};

extern int tresultToApiError(TResult result);

#endif // SWANLINK_FINANCE_CARDSENDER_ADAPTOR_F5G006_LIB_LIBF5G006_INCLUDE_F5G006_DS_H
